<template>
  <div>
    <!-- 渲染角色列表 -->
    <el-checkbox-group v-model="roleIdArr">
      <el-checkbox v-for="item in roleList" :key="item.id" :label="item.id">
        {{ item.name }}
      </el-checkbox>
    </el-checkbox-group>

    <el-row class="footer" type="flex" justify="center">
      <el-col :span="6">
        <el-button type="primary" size="small" @click="enterFn">确定</el-button>
        <el-button size="small" @click="cancleDialog">取消</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: 'AssignRole',
  props: {
    // 所有-角色列表
    roleList: {
      type: Array,
      default: _ => []
    },
    roleIds: { // 选中id
      type: Array,
      default: _ => []
    }
  },
  data() {
    return {
      roleIdArr: [] // 保存当前选中的权限列表
    }
  },
  watch: {
    roleIds() {
      this.roleIdArr = [...this.roleIds]
    }
  },
  methods: {
    // 取消弹框
    cancleDialog() {
      this.$emit('close')
    },
    // 确定弹框
    enterFn() {
      this.$emit('confirmEv', this.roleIdArr)
      this.$emit('close')
    }
  }
}
</script>

<style lang="scss" scoped>
.footer {
  margin-top: 30px;
}
</style>
